home *** CD-ROM | disk | FTP | other *** search
- Path: news.salford.ac.uk!aber!not-for-mail
- From: pcg@aber.ac.uk (Piercarlo Grandi)
- Newsgroups: comp.lang.c++,comp.object,comp.object.logic
- Subject: Re: polymorphism
- Date: 27 Mar 1996 19:49:43 +0000
- Organization: Prifysgol Cymru, Aberystwyth
- Sender: pcg@osfb.aber.ac.uk
- Message-ID: <vwjvijql3jc.fsf@osfb.aber.ac.uk>
- References: <31513CBB.41C6@mi.leeds.ac.uk> <3151DCF0.3EAA@staff.ichange.com>
- Reply-To: pcg@aber.ac.uk (Piercarlo Grandi)
- NNTP-Posting-Host: osfb.aber.ac.uk
- In-reply-to: Jesse Liberty's message of Thu, 21 Mar 1996 17:49:20 -0500
- X-Newsreader: Gnus v5.0.15
-
- >>> On Thu, 21 Mar 1996 17:49:20 -0500, Jesse Liberty
- >>> <jl@staff.ichange.com> said:
-
- jl> Aniko Simon wrote:
-
- Aniko> Can anyone help: what does the term "polymorphism" mean in OO
- Aniko> programming ?
-
- jl> Polymorphism refers to the ability to take more than one form.
-
- In Greek mythology and in nethack, oh yes.
-
- But in OO programming it means exactly the opposite: the ability to
- maintain exactly the same form, as you actually describe a bit
- imprecisely but correctly:
-
- jl> The idea is that the user of an object can deal with an abstract
- jl> interface and the individual implementation "does the right thing."
-
- This is imprecise because it only describes one of the two very
- different things that are usually called polymorphism (ad hoc): the
- ability of the *same* interface to be applied to values of different
- types, which is called overloading. For example:
-
- 2 + 3 == 5
-
- "a" + "b" == "ab"
-
- The *same* symbols, '+' and '==' can without change be applied both to
- integers and strings, because as interfaces they are associated with
- very different implementations.
-
- There is another concept that is also called (proper) polymorphism, and
- it is genericity, that is the ability of the *same* implementation to
- apply to values of different types. For example:
-
- (lambda (a b) (if (> a b) a b))
-
- is generic wrt any type for which '>' is defined, because the *same*
- implementation can be used for any of them.
-
- jl> For example, you might tell a window to draw and have it draw
- jl> properly whether it is a frame, a subwindow, a button, or a check
- jl> box. The different "forms" of the window all do the right thing in
- jl> their own context.
-
- This is completely wrong: windows don't to anything, what happens is
- that the same interface resolves to different implementations depending
- on the type of window, nothing changes form at all, despite the
- misnomer.
-
- It is unfortunate that in OO ``polymorphism'' indicates exactly the
- opposite of what it means in literature, but it is very important to
- realize that, because the ability to apply the same interface or the
- same implementation, _without_ change of form, to values of different
- types allows higher reuse of code, which is supposedly a good idea.
-